package com.ruoyi.web.controller.animal;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.animal.domain.AnimalInfo;
import com.ruoyi.animal.service.IAnimalInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 寄养动物信息Controller
 *
 * @author zhezhi
 * @date 2022-10-02
 */
@RestController
@RequestMapping("/commerce/animal")

public class AnimalInfoController extends BaseController
{
    @Autowired
    private IAnimalInfoService animalInfoService;

    /**
     * 查询寄养动物信息列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:list')")
    @GetMapping("/list")
    @ApiOperation("查询寄养动物信息列表")
    public TableDataInfo list(AnimalInfo animalInfo)
    {
        startPage();
        List<AnimalInfo> list = animalInfoService.selectAnimalInfoList(animalInfo);
        return getDataTable(list);
    }

    /**
     * 导出寄养动物信息列表
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:export')")
    @Log(title = "寄养动物信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation("导出寄养动物信息列表")
    public void export(HttpServletResponse response, AnimalInfo animalInfo)
    {
        List<AnimalInfo> list = animalInfoService.selectAnimalInfoList(animalInfo);
        ExcelUtil<AnimalInfo> util = new ExcelUtil<AnimalInfo>(AnimalInfo.class);
        util.exportExcel(response, list, "寄养动物信息数据");
    }

    /**
     * 获取寄养动物信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:query')")
    @GetMapping(value = "/{animalId}")
    @ApiOperation("获取寄养动物信息详细信息")
    public AjaxResult getInfo(@PathVariable("animalId") Long animalId)
    {
        return AjaxResult.success(animalInfoService.selectAnimalInfoByAnimalId(animalId));
    }

    /**
     * 新增寄养动物信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:add')")
    @Log(title = "寄养动物信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增寄养动物信息")
    public AjaxResult add(@RequestBody AnimalInfo animalInfo)
    {
        return toAjax(animalInfoService.insertAnimalInfo(animalInfo));
    }

    /**
     * 修改寄养动物信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:edit')")
    @Log(title = "寄养动物信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改寄养动物信息")
    public AjaxResult edit(@RequestBody AnimalInfo animalInfo)
    {
        return toAjax(animalInfoService.updateAnimalInfo(animalInfo));
    }

    /**
     * 删除寄养动物信息
     */
    @PreAuthorize("@ss.hasPermi('commerce:animal:remove')")
    @Log(title = "寄养动物信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{animalIds}")
    @ApiOperation("删除寄养动物信息")
    public AjaxResult remove(@PathVariable Long[] animalIds)
    {
        return toAjax(animalInfoService.deleteAnimalInfoByAnimalIds(animalIds));
    }
}
